wifi.setmode(wifi.STATION) 
wifi.sta.config({ssid="admin123", pwd="12345678"}) 
wifi.sta.connect()  


function start_udpserver()
    udpSocket = net.createUDPSocket()
    udpSocket:listen(5000)
    udpSocket:on("receive" , function(s,data,port,ip)
        print(string.format("received '%s'from %s:%d",data,ip,port))
        s:send(port, ip, data .. " OK ")
    end)
    port, ip = udpSocket:getaddr()
    print(string.format("local UDP socket address / port: %s:%d", ip, port))
end

mytmr = tmr.create()
mytmr:alarm(500,tmr.ALARM_AUTO,function ()
    wifi_ip = wifi.sta.getip()
    if wifi_ip ~= nil then
        print(wifi_ip)
        mytmr:stop()
        start_udpserver()   
    end
    print("----getip------")
end)

